import { CommontListResp } from '@/api/types'
import request, { ApiResponse } from '@/utils/service/request'
import {
  BatchBindTagClassReq,
  OptionTagReq,
  QueryTagReq,
  TagItem,
} from './model/tagModel'

export enum TagApi {
  QUERY_TAG_LIST = '/paixin-admin/tag/search',
  /** 添加或修改标签 */
  OPTION_TAG = '/paixin-admin/tag/save',
  /** 批量绑定分类和标签 */
  BATCH_BIND_TAG_CLASS = '/paixin-admin/tag/ref/add/batch',
  /** 标签删除-批量 */
  BATCH_DELETE_TAG = '/paixin-admin/tag/delete/batch',
  /** 标签与分类关系删除-批量 */
  BATCH_DELETE_TAGCLASS_REF = '/paixin-admin/tag/ref/delete/batch',
}

export function fetchTagList(body: QueryTagReq) {
  return request.post<ApiResponse<CommontListResp<TagItem>>>(
    TagApi.QUERY_TAG_LIST,
    body
  )
}

export function optionTag(body: OptionTagReq) {
  return request.post<ApiResponse<TagItem>>(TagApi.OPTION_TAG, body)
}

export function batchBindCategory(body: BatchBindTagClassReq) {
  return request.post<ApiResponse<null>>(TagApi.BATCH_BIND_TAG_CLASS, body)
}

export function batchDeleteTag(tagIds: string[]) {
  return request.post<ApiResponse<null>>(TagApi.BATCH_DELETE_TAG, tagIds)
}

export function batchDelTagClassRef(refIds: string[]) {
  return request.post<ApiResponse<null>>(
    TagApi.BATCH_DELETE_TAGCLASS_REF,
    refIds
  )
}
